package com.wjcxf.utils;

import java.util.Random;

public class CalcUtil {
    private static volatile Random random;
    public static final int[][] abList = {{0,0},{1,0},{0,1},{1,1},{2,0},{0,2},{2,1},{1,2},{2,2},{1,3},{4,0},{0,4}};
    static {
        random =  new Random();
    }
    public static int getRandomNumber(int low,int high){
        if(low > high){
            low ^= high;
            high ^= low;
            low ^= high;
        }
        //[0,height-low] +low
        //[low,height]
        return CalcUtil.random.nextInt(high - low + 1) + low;
    }
    //没有Math.pow(int,int)的重载
    public static int pow(int base, int exponent){
        if(base == 0) return 0;
        if(exponent == 0) return 1;
        int absExponent = (exponent < 0)? exponent * -1 : exponent;
        int result = base;
        for(int i = 1; i < absExponent; i++) {
            result *= base;
        }
        return result;
    }


    public static double pow(double base, double exponent){
        return Math.pow(base,exponent);
    }

    //换底公式
    public static double log(double value, double base) {
        return Math.log(value) / Math.log(base);
    }


}
